package io.renren.modules.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.company.dao.PersonDao;
import io.renren.modules.company.dto.CompanyDTO;
import io.renren.modules.company.dto.PersonDTO;
import io.renren.modules.company.entity.CompanyEntity;
import io.renren.modules.company.entity.PersonEntity;
import io.renren.modules.company.service.PersonService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 员工
 *
 * @author tree
 * @since 1.0.0 2024-12-24
 */
@Service
public class PersonServiceImpl extends CrudServiceImpl<PersonDao, PersonEntity, PersonDTO> implements PersonService {

    @Override
    public QueryWrapper<PersonEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<PersonEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public PersonDTO get(String personname) {
        QueryWrapper<PersonEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(personname), "personname", personname);
        PersonEntity companyEntity = baseDao.selectOne(wrapper);
        return ConvertUtils.sourceToTarget(companyEntity, PersonDTO.class);
    }

    @Override
    public List<PersonDTO> getByCompany(String companyname) {
        QueryWrapper<PersonEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(companyname), "companyname", companyname);
        List<PersonEntity> companyList = baseDao.selectList(wrapper);
        return ConvertUtils.sourceToTarget(companyList, PersonDTO.class);
    }
}